/**
 * 枚举
 *
 */
use std::fmt::*;

fn Enumeration() {
    #[derive(Debug)]
    enum IPKind {
        IPv4,
        IPv6,
    }
    let four = IPKind::IPv4;
    let six = IPKind::IPv6;
    println!("{:?} {:?}", four, six);
    struct IPAddress {
        kind: IPKind,
        address: String,
    }
    impl Display for IPAddress {
        fn fmt(&self, f: &mut Formatter) -> Result {
            write!(f, "{}", self.address)
        }
    }
    let local = IPAddress {
        kind: IPKind::IPv4,
        address: String::from("127.0.0.1"),
    };
    let lookback = IPAddress {
        kind: IPKind::IPv6,
        address: String::from("::1"),
    };
    println!("{} {}", local, lookback);
    #[derive(Debug)]
    enum IPAddr {
        V4(u8, u8, u8, u8),
        V6(String),
    }

    let local = IPAddr::V4(127, 0, 0, 1);
    let lookback = IPAddr::V6(String::from("::1"));
    println!("{:?} {:?}", local, lookback);
}
pub fn test() {
    use std::net::*;
    let ip = IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1));
    println!("{:#?}", ip);
    let ip6 = IpAddr::V6(Ipv6Addr::new(9, 8, 7, 6, 5, 4, 3, 2));
    println!("{:#?}", ip6);
}
